<!--
 * @Author: Ryan
 * @Date: 2021-05-27 16:19:52
 * @LastEditors: Ryan
 * @LastEditTime: 2021-05-28 16:04:35
 * @Description: 拷贝文本
 * @FilePath: /ztky-care-page/src/views/example/clipboard/index.vue
-->

<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="使用方法进行复制" name="directly">
        <el-input v-model="inputData" class="mr-10" placeholder="Please input" style="width:400px;max-width:100%;" />
        <el-button type="primary" icon="el-icon-document" @click="handleCopy(inputData,$event)">
          复制
        </el-button>
      </el-tab-pane>
      <el-tab-pane label="使用v-directive指令进行复制" name="v-directive">
        <el-input v-model="inputData" class="mr-10" placeholder="Please input" style="width:400px;max-width:100%;" />
        <el-button v-clipboard:copy="inputData" v-clipboard:success="clipboardSuccess" type="primary" icon="el-icon-document">
          复制
        </el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import clip from '@/utils/clipboard'
// import clipboard from '@/directive/clipboard/index.js'

export default {
  name: 'ClipboardDemo',
  // directives: {
  //   clipboard
  // },
  data() {
    return {
      activeName: 'directly',
      inputData: 'https://github.com/vuejs/vue'
    }
  },
  methods: {
    handleCopy(text, event) {
      clip(text, event)
    },
    clipboardSuccess() {
      this.$message({
        message: '复制成功',
        type: 'success',
        duration: 1500
      })
    }
  }
}
</script>

